import "package:flutter/material.dart";
import "package:myapp/pages/homePage.dart";

class FormPage extends StatefulWidget {
  final Map? arguments; //上个页面跳转进来的参数
  const FormPage({super.key, this.arguments});
  @override
  State<FormPage> createState() => FormPageState();
}

class FormPageState extends State<FormPage> {
  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    print(widget.arguments);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('表单'),
      ),
      body: Column(
        children: [
          ElevatedButton(
              onPressed: () {
                Navigator.of(context).pop();
              },
              child: const Text('返回上一级')),
          ElevatedButton(
              onPressed: () {
                Navigator.of(context).pushReplacementNamed('/search');
              },
              child: const Text('替换路由跳转search')),
          ElevatedButton(
              onPressed: () {
                Navigator.of(context).pushAndRemoveUntil(
                    MaterialPageRoute(builder: (BuildContext context) {
                  return const HomePage(); //如果但会路由可返回上一级路由操作时，会出现黑屏
                }), (route) => false);
              },
              child: const Text('关闭所有页面，并返回指定路由home')),
        ],
      ),
    );
  }
}
